package com.activity.myfirstapp;

import com.example.myfirstapp.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {
	public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.menu_settings:
            	showSettings();
                return true;
            case R.id.menu_about:
                showAbout();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
    
    /** Called when the user clicks the Send button */
    public void sendMessage(View view) {
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        EditText editText = (EditText) findViewById(R.id.edit_message);
        String message = editText.getText().toString();
        
        if(message.contains("rami") || message.contains("sumbul") ||
       	   message.contains("Rami") || message.contains("Sumbul"))
        	message = message.concat(" is awesome :)");
        else
        	message = message.concat(" is lame :(");
        
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }
    
    /** Shows settings screen */
    public void showSettings() {
        Intent intent = new Intent(this, DisplaySettingsActivity.class);
        startActivity(intent);
    }
    
    /** Shows about screen */
    public void showAbout() {
        Intent intent = new Intent(this, DisplayAboutActivity.class);
        startActivity(intent);
    }
}
